home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / cd-sup / classact / examples / radiobutton / radioexample.c < prev    next >
C/C++ Source or Header  |  1999-01-01  |  5KB  |  232 lines

  1. ;/* RadioButton Example
  2. sc link radioexample.c lib lib:classact.lib
  3. quit
  4. */
  5.  
  6. /**
  7.  **  RadioExample.c -- radiobutton class example.
  8.  **
  9.  **  This is a simple example testing some of the capabilities of the
  10.  **  radiobutton gadget class.
  11.  **
  12.  **  This opens a window with radio button gadget. We will usse ClassAct.lib's
  13.  **  RadioButtons() and FreeRadioButtons() utility functions to create the
  14.  **  item labels.
  15.  **
  16.  **/
  17.  
  18. /* system includes
  19.  */
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23.  
  24. #include <exec/types.h>
  25. #include <exec/memory.h>
  26. #include <intuition/intuition.h>
  27. #include <intuition/gadgetclass.h>
  28. #include <graphics/gfxbase.h>
  29. #include <graphics/text.h>
  30. #include <graphics/gfxmacros.h>
  31. #include <utility/tagitem.h>
  32. #include <workbench/startup.h>
  33. #include <workbench/workbench.h>
  34.  
  35. #include <proto/intuition.h>
  36. #include <proto/graphics.h>
  37. #include <proto/exec.h>
  38. #include <proto/dos.h>
  39. #include <proto/utility.h>
  40. #include <proto/wb.h>
  41. #include <proto/icon.h>
  42.  
  43. /* ClassAct includes
  44.  */
  45. #include <classact.h>
  46.  
  47. /* button option texts
  48.  */
  49. UBYTE *radio[] =
  50. {
  51.     "2400",
  52.     "9600",
  53.     "19200",
  54.     "38400",
  55.     NULL
  56. };
  57.  
  58. enum
  59. {
  60.     GID_MAIN=0,
  61.     GID_RADIOBUTTON,
  62.     GID_QUIT,
  63.     GID_LAST
  64. };
  65.  
  66. enum
  67. {
  68.     WID_MAIN=0,
  69.     WID_LAST
  70. };
  71.  
  72. enum
  73. {
  74.     OID_MAIN=0,
  75.     OID_LAST
  76. };
  77.  
  78. #define FMIN 0
  79. #define FMAX 100
  80.  
  81. int main(void)
  82. {
  83.     struct MsgPort *AppPort;
  84.  
  85.     struct Window *windows[WID_LAST];
  86.  
  87.     struct Gadget *gadgets[GID_LAST];
  88.  
  89.     Object *objects[OID_LAST];
  90.  
  91.     struct List *radiolist;
  92.  
  93.     /* make sure our classes opened... */
  94.     if (!ButtonBase || !RadioButtonBase || !WindowBase || !LayoutBase)
  95.         return(30);
  96.     else if ( AppPort = CreateMsgPort() )
  97.     {
  98.         /* Create radiobutton label list.
  99.          */
  100.         radiolist = RadioButtons( "1200","2400","4800","9600","19200","38400","57600", NULL );
  101.  
  102.         if (radiolist)
  103.         {
  104.             /* Create the window object.
  105.              */
  106.             objects[OID_MAIN] = WindowObject,
  107.                 WA_ScreenTitle, "ClassAct Release 2.0",
  108.                 WA_Title, "ClassAct RadioButton Example",
  109.                 WA_Activate, TRUE,
  110.                 WA_DepthGadget, TRUE,
  111.                 WA_DragBar, TRUE,
  112.                 WA_CloseGadget, TRUE,
  113.                 WA_SizeGadget, TRUE,
  114.                 WINDOW_IconifyGadget, TRUE,
  115.                 WINDOW_IconTitle, "RadioButton",
  116.                 WINDOW_AppPort, AppPort,
  117.                 WINDOW_Position, WPOS_CENTERMOUSE,
  118.                 WINDOW_ParentGroup, gadgets[GID_MAIN] = VGroupObject,
  119.                     LAYOUT_SpaceOuter, TRUE,
  120.                     LAYOUT_DeferLayout, TRUE,
  121.  
  122.                     LAYOUT_AddChild, VGroupObject,
  123.                         LAYOUT_SpaceOuter, TRUE,
  124.                         LAYOUT_BevelStyle, BVS_GROUP,
  125.                         LAYOUT_Label, "Baud Rate",
  126.  
  127.                         LAYOUT_AddChild, gadgets[GID_RADIOBUTTON] = RadioButtonObject,
  128.                             GA_ID, GID_RADIOBUTTON,
  129.                             GA_RelVerify, TRUE,
  130.                             RADIOBUTTON_Labels, radiolist,
  131.                             RADIOBUTTON_Selected, 0,
  132.                         RadioButtonEnd,
  133.                     //    CHILD_WeightedHeight, 0,
  134.                     LayoutEnd,
  135.  
  136.                     LAYOUT_AddChild, ButtonObject,
  137.                         GA_ID, GID_QUIT,
  138.                         GA_RelVerify, TRUE,
  139.                         GA_Text,"_Quit",
  140.                     ButtonEnd,
  141.                     CHILD_WeightedHeight, 0,
  142.  
  143.                 EndGroup,
  144.             EndWindow;
  145.  
  146.               /*  Object creation sucessful?
  147.                */
  148.             if (objects[OID_MAIN])
  149.             {
  150.                 /*  Open the window.
  151.                  */
  152.                 if (windows[WID_MAIN] = (struct Window *) CA_OpenWindow(objects[OID_MAIN]))
  153.                 {
  154.                     ULONG wait, signal, app = (1L << AppPort->mp_SigBit);
  155.                     ULONG done = FALSE;
  156.                     ULONG result;
  157.                     UWORD code;
  158.  
  159.                      /* Obtain the window wait signal mask.
  160.                      */
  161.                     GetAttr(WINDOW_SigMask, objects[OID_MAIN], &signal);
  162.  
  163.                     /* Input Event Loop
  164.                      */
  165.                     while (!done)
  166.                     {
  167.                         wait = Wait( signal | SIGBREAKF_CTRL_C | app );
  168.  
  169.                         if ( wait & SIGBREAKF_CTRL_C )
  170.                         {
  171.                             done = TRUE;
  172.                         }
  173.                         else
  174.                         {
  175.                             while ( (result = CA_HandleInput(objects[OID_MAIN], &code) ) != WMHI_LASTMSG )
  176.                             {
  177.                                 switch (result & WMHI_CLASSMASK)
  178.                                 {
  179.                                     case WMHI_CLOSEWINDOW:
  180.                                         windows[WID_MAIN] = NULL;
  181.                                         done = TRUE;
  182.                                         break;
  183.  
  184.                                     case WMHI_GADGETUP:
  185.                                         switch (result & WMHI_GADGETMASK)
  186.                                         {
  187.                                             case GID_QUIT:
  188.                                                 done = TRUE;
  189.                                                 break;
  190.                                         }
  191.                                         break;
  192.  
  193.                                     case WMHI_ICONIFY:
  194.                                         CA_Iconify(objects[OID_MAIN]);
  195.                                         windows[WID_MAIN] = NULL;
  196.                                         break;
  197.  
  198.                                     case WMHI_UNICONIFY:
  199.                                         windows[WID_MAIN] = (struct Window *) CA_OpenWindow(objects[OID_MAIN]);
  200.  
  201.                                         if (windows[WID_MAIN])
  202.                                         {
  203.                                             GetAttr(WINDOW_SigMask, objects[OID_MAIN], &signal);
  204.                                         }
  205.                                         else
  206.                                         {
  207.                                             done = TRUE;    // error re-opening window!
  208.                                         }
  209.                                          break;
  210.                                 }
  211.                             }
  212.                         }
  213.                     }
  214.                 }
  215.  
  216.                 /* Disposing of the window object will also close the window if it is
  217.                  * already opened, and it will dispose of the layout object attached to it.
  218.                  */
  219.                 DisposeObject(objects[OID_MAIN]);
  220.             }
  221.  
  222.             /* free the radiobutton list
  223.              */
  224.             FreeRadioButtons(radiolist);
  225.         }
  226.  
  227.         DeleteMsgPort(AppPort);
  228.     }
  229.  
  230.     return(0);
  231. }
  232.